<?php TPL::output('m/header_meta.tpl.htm'); ?>
<div class="searchbox" style="padding: 5px 12px;">
    <form id="search_form" action="m/search/" method="post">
        <div class="searchinfo w_box">
            <input name="q" placeholder="搜索" type="text">
        </div>
    </form>
</div>
<!--tab-->
<div class="phb_two">
    <a class="tab <?php if (!$this->user_id) { ?>cur<?php } ?>" type="all">全部话题</a>
    <?php if ($this->user_id) { ?>
    <a class=" tab" type="focus">已关注话题</a>
    <?php } ?>
</div>
<!--tab end-->
<!--关注列表-->
<div class="nlists " id="nlists">
</div>
<div class="flow-default follow" id="demo">
</div>
<!--推荐列表end-->
<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', '.follow>h3', function (k) {
            if ($(this).hasClass('current')) {
                $(this).parent().find('dl').hide();
                $(this).find('.showdown').html('<img src="<?php echo base_url();?>/static/mobile/images/sq.png">展开');
                $(this).removeClass('current');
            } else {
                $(this).parents('nlists').find('h3').removeClass("current");
                $(this).addClass('current');
                $(this).find('.showdown').html('<img src="<?php echo base_url();?>/static/mobile/images/open_ico.png">收起');

                $(this).parent().find('dl').show();
            }
        });
        $(document).on('click', '.d_right a', function () {
            var topic_id = $(this).attr('topic_id');
            var type = $(this).attr('type');
            var uid = "<?php echo $this->user_id;?>";
            if (uid) {
                if (topic_id)
                    AWS.User.follow($(this), 'topic', topic_id, '<?php echo new_post_hash();?>');
            } else {
                setTimeout(alert('请先登录'));
                window.location = "?/m/login/";
            }
        });
    });
</script>

<script src="<?php echo base_url();?>/static/mobile/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('flow', function () {
        var $ = layui.jquery;
        var flow = layui.flow;
        var page_focus = 0;
        var page_all = 1;
        var flag_focus = 1;
        var flag_all = 1;
        $("#demo").hide();
        $(".tab").each(function (i) {
            $(this).on('click', function (k) {
                var type = $(this).attr('type');
                $(this).addClass('cur').siblings().removeClass('cur');
                var uid = "<?php echo $this->user_id;?>";
                var keyword = "<?php echo $this->keyword;?>";
                if (type == 'focus') {
                    $(".nlists").hide();
                    $("#demo").show();

                    if(flag_focus){
                        flag_focus=0
                        var url = G_BASE_URL + '/m/ajax/search_focus_topics/';
                        flow.load({
                            elem: '#demo',
                            end: 'SORRY~!没有了',
                            done: function (page, next) {
                                if ($(".nlists").is(':visible')) {
                                    next();
                                    return false
                                }
                                var lis = [];
                                var page = page - 1;
                                $.get(url + '?page=' + page_focus, function (res) {
                                    page_focus++
                                    if (res.pages) {
                                        if (eval(res.data).length < 1) {
                                            AWS.DingTalk.showToast('', '暂无更多内容');
                                        }
                                        var html = '';

                                        layui.each(res.data, function (index, item) {
                                            html += '<dl><dt><img src="' + item.topic_pic + '"></dt>' +
                                                '<a href="topic/' + item.topic_id + '"><dd class="d_center">' +
                                                '<h4>' + item.topic_title + '</h4>' +
                                                '<p><span>' + item.focus_count + '人关注</span></p>' +
                                                '</dd></a><dd class="d_right"><a type="off" class="active">√ 已关注</a></dd>' +
                                                '<div class="clear"></div></dl>';
                                        });
                                        lis.push(html);
                                        next(lis.join(''), page < res.pages);
                                    } else {
                                        $('.layui-flow-more').remove();
                                        $('.flow-default').html('<div class="mod-body"><ul id="best_answers_listview"><p style="padding: 15px 0" align="center">没有内容</p></ul></div>');
                                    }
                                }, 'json');
                            }
                        });
                    }
                } else {
                    $("#demo").hide();
                    $(".nlists").show();

                    if(flag_all){

                        flag_all=0
                        var url = G_BASE_URL + '/m/ajax/search_hot_topics/';
                        flow.load({
                            elem: '#nlists',
                            end: 'SORRY~!没有了',
                            done: function (page, next) {
                                if ($("#demo").is(':visible')) {
                                    next();
                                    return false
                                }
                                var lis2 = [];
                                $.ajax({
                                    url: url,
                                    type: 'GET',
                                    data: {search_type: type, keyword: keyword, page: page_all},
                                    async: false,
                                    dataType: 'json',
                                    success: function (res) {
                                        page_all++
                                        lis2.push(res.data);
                                        next(lis2.join(''), page < res.pages);
                                    }
                                })
                            }
                        });
                    }
                }
            })
        });
        $(".tab").eq(0).click();
    });
</script>
<?php TPL::output('m/footer.tpl.htm'); ?>


